package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.ip.AddressUtils;
import com.ruoyi.common.utils.ip.IpUtils;
import com.ruoyi.system.domain.SysErrorLog;
import com.ruoyi.system.mapper.SysErrorLogMapper;
import com.ruoyi.system.service.SysErrorLogService;
import eu.bitwalker.useragentutils.UserAgent;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 系统访问记录(SysErrorLog)表服务实现类
 *
 * @author simple
 * @since 2024-02-02 16:27:09
 */
@Service("sysErrorLogService")
public class SysErrorLogServiceImpl extends ServiceImpl<SysErrorLogMapper, SysErrorLog> implements SysErrorLogService {

	public void logError(String username, String message, String className, String methodName) {
		log(username, message, className, methodName, SysErrorLog.ERROR);
	}

	public void logWarning(String username, String message, String className, String methodName) {
		log(username, message, className, methodName, SysErrorLog.WARNING);
	}

	public void log(String username, String message, String className, String methodName,String status) {
		// 封装对象
		SysErrorLog errorLog = new SysErrorLog();
		errorLog.setUserName(username);
		errorLog.setMsg(message);
		errorLog.setStatus(status);
		errorLog.setCreateTime(new Date());
		errorLog.setClassName(className);
		errorLog.setMethodName(methodName);

		save(errorLog);
	}

}

